package com.mall.b2c.interceptor;

import com.mall.b2c.Constants;
import com.mall.common.util.CookieUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 邀请人拦截器
 */
public class InviterInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String inviter = request.getParameter(Constants.INVITE_COOKIE_NAME);
		if(StringUtils.isNotEmpty(inviter)) {
			CookieUtils.addCookie(request, response, Constants.INVITE_COOKIE_NAME, inviter);
		}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
	}
	
}